<template>
  <suncaper-layout
    theme="light"
    :logo="logo"
    :sidebar-list="sidebarList"
    :logout="logout"
  />
</template>

<script>
import { mapGetters } from 'vuex';
import Layout from '@/layouts/Layout';
import logo from '@/assets/images/xjtu_logo.png';

export default {
  name: 'Main',
  data() {
    return {
      logo: {
        src: logo,
        alt: '上程数据',
        firstDes: 'Xjtu集约化',
        secondDes: '后台管理平台',
      },
    };
  },
  computed: {
    ...mapGetters({
      userType: 'user/getUserType',
      getSidebarList: 'sidebar/getSidebarList',
    }),
    sidebarList() {
      return this.getSidebarList(this.userType).main;
    },
  },
  methods: {
    logout() {
      this.$store.commit('user/SET_USER_ID', null);
      this.$store.commit('user/SET_USER_NAME', '');
      this.$store.commit('user/SET_USER_TYPE', null);
      localStorage.removeItem('id');
      localStorage.removeItem('name');
      localStorage.removeItem('type');
      localStorage.removeItem('token');

      this.$router.replace('/');
    },
  },
  components: {
    'suncaper-layout': Layout,
  },
};
</script>
